﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMPLib;

namespace demo01
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
                playlist.Items.Clear();
                playlist.Items.Add(openFileDialog1.FileName);
            }
        }

        private void addMediaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            playlist.Items.Clear();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                foreach (string media in openFileDialog1.FileNames)
                {
                    playlist.Items.Add(media);
                }
            }
            
            if (axWindowsMediaPlayer1.playState== WMPPlayState.wmppsStopped|| axWindowsMediaPlayer1.playState == WMPPlayState.wmppsWaiting
                ||axWindowsMediaPlayer1.playState == WMPPlayState.wmppsPlaying || axWindowsMediaPlayer1.playState == WMPPlayState.wmppsUndefined)
            {
                playlist.SelectedIndex = 0;
                axWindowsMediaPlayer1.URL = playlist.Items[0].ToString();
            }
        }

        private void playlist_SelectedIndexChanged(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.URL = playlist.Items[playlist.SelectedIndex].ToString();
        }

        private void playToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

        private void pauseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
        }

        private void stopToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }

        private void nextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            playlist.SelectedIndex = playlist.SelectedIndex + 1;
        }
    }
}
